package com.ruoyi.goods.controller;

import java.util.Date;
import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.goods.domain.BmBrand;
import com.ruoyi.goods.service.IBmBrandService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 商品品牌Controller
 * 
 * @author ruoyi
 * @date 2023-08-03
 */
@RestController
@RequestMapping("/brand")
public class BmBrandController extends BaseController
{
    @Autowired
    private IBmBrandService bmBrandService;

    /**
     * 查询商品品牌列表
     */
    @RequiresPermissions("ruoyi-goods:brand:list")
    @GetMapping("/list")
    public TableDataInfo list(BmBrand bmBrand) throws IOException {
        startPage();
//        Thumbnails.of("d:/picture"+bmBrand.getBrandImg()).scale(0.25f).toFile("d:/images"+new Date().getTime());
        //Thumbnails.of("原图片路径").scale(缩放比例).toFile("输出路径");
        System.out.println("Current time in milliseconds: " + new Date().getTime());
        List<BmBrand> list = bmBrandService.selectBmBrandList(bmBrand);
        return getDataTable(list);
    }
    @GetMapping("/bNameList")
    public AjaxResult bNameList(BmBrand bmBrand) {
        List<BmBrand> list = bmBrandService.selectBmBrandList(bmBrand);
        return AjaxResult.success(list);
    }

    /**
     * 导出商品品牌列表
     */
    @RequiresPermissions("ruoyi-goods:brand:export")
    @Log(title = "商品品牌", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BmBrand bmBrand)
    {
        List<BmBrand> list = bmBrandService.selectBmBrandList(bmBrand);
        ExcelUtil<BmBrand> util = new ExcelUtil<BmBrand>(BmBrand.class);
        util.exportExcel(response, list, "商品品牌数据");
    }

    /**
     * 获取商品品牌详细信息
     */
    @RequiresPermissions("ruoyi-goods:brand:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(bmBrandService.selectBmBrandById(id));
    }

    /**
     * 新增商品品牌
     */
    @RequiresPermissions("ruoyi-goods:brand:add")
    @Log(title = "商品品牌", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BmBrand bmBrand)
    {
        return toAjax(bmBrandService.insertBmBrand(bmBrand));
    }

    /**
     * 修改商品品牌
     */
    @RequiresPermissions("ruoyi-goods:brand:edit")
    @Log(title = "商品品牌", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BmBrand bmBrand)
    {
        return toAjax(bmBrandService.updateBmBrand(bmBrand));
    }

    /**
     * 删除商品品牌
     */
    @RequiresPermissions("ruoyi-goods:brand:remove")
    @Log(title = "商品品牌", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bmBrandService.deleteBmBrandByIds(ids));
    }
}
